#include "line.h"
#include "cineplex.h"

Line::Line()
{
	customers = new IterList();
	isOpen = 1;
	myType = 0;
}

Line::~Line()
{
	delete customers;
}

void Line::Enqueue(Customer* cust)
{
	customers->Append(cust);
	//wake clerk
	if(myType == 1)
	{
		TicketClerk* clerk = ((TicketClerk*)myClerk);
		clerk->sleepCon->Broadcast(clerk->msgLock);
	}else if(myType == 2)
	{
		FoodClerk* clerk = ((FoodClerk*)myClerk);
		clerk->sleepCon->Broadcast(clerk->msgLock);
	}else{
		TicketTaker* clerk = ((TicketTaker*)myClerk);
		clerk->sleepCon->Broadcast(clerk->msgLock);
	}
}

void Line::Dequeue(Customer* cust)
{
	int index = FindInLine(cust);
	if(index != -1) customers->Pop(index);
}

int Line::FindInLine(Customer* cust)
{
	for(int i = 0; i< getSize(); i++)
	{
		if(customers->Get(i) == cust) return i;
	}
	return -1;
}

int Line::getSize()
{
	if(!isOpen) return -1;
	return customers->getSize();
}

void Line::Clear()
{
	customers->Clear();
}
